'''
Created on Apr 5, 2011

@author: georgeholler
'''
  
import argparse
import getpass
class Options:
    
    def __init__(self):
        self.action = None
        self.appid = None
        self.host = None
        self.email = None
        self.password = None
        self.file = None
        self.entities = None
        self.fetch_count = 100

    def parse(self, argv):
        parser = argparse.ArgumentParser(description='Adept')
        parser.add_argument('-action', required=True, choices=['backup', 'restore', 'delete', 'export', 'clear-cache'])
        parser.add_argument('-appid', required=True, help='The App Id for the app instance.')
        parser.add_argument('-host', help='The host for the app instance')
        parser.add_argument('-email', required=True, help='The email for the app account.')
        parser.add_argument('-password', help='The password for the app account.')
        parser.add_argument('-file', help='Output or input file for actions: backup, restore')   
        parser.add_argument('-entities', help='Comma separated list of entities to act on for actions: backup, restore, delete, export')   
        parser.add_argument('-fetch_count', type=int, default=100, help='range 1..1000, action: delete')
        args = parser.parse_args(argv)
        self.action = args.action
        self.appid = args.appid
        self.host = args.host
        if self.host is None:
            self.host = '%s.appspot.com' % self.appid
        self.email = args.email
        self.password = args.password
        self.file = args.file
        self.fetch_count = args.fetch_count
        if self.fetch_count > 1000:
            self.fetch_count = 1000
        if self.fetch_count < 1:
            self.fetch_count = 1
        self.entities = args.entities
        if not self.entities is None:
            self.entities = self.entities.split(',')        
        if self.password is None:
            self.password = getpass.getpass('Enter password:')
            args.password = self.password
        print str(args)
        
# end